{% extends 'index/base.html' %}

{% block title %}订阅市场{% endblock %}

{% block content %}
  <section class="pt-5">
    <div class="wow fadeIn">
      <h2 class="h1 text-center mb-5">订阅市场</h2>
      <div>
          {% for category in categories %}
          <a class="btn btn-info btn-sm waves-effect waves-light" href="{{ url_for('poly.market', category=category.id) }}">{{ category.title }}</a>
          {% endfor %}
      </div>
    </div>
    <hr class="my-5">
    {% if items.count() != 0 %}
    {% for item in items %}
        <div class="row mt-3 wow fadeIn">
          <!--Grid column-->
          <div class="col-lg-5 col-xl-4 mb-4">
            <!--Featured image-->
            <div class="view overlay rounded z-depth-1">
              <img src="{{ url_for('poly.get_cover', filename=item.image) }}" class="card-img-top" width="350" height="180" alt="">
            </div>
          </div>
          <!--Grid column-->

          <!--Grid column-->
          <div class="col-lg-7 col-xl-7 ml-xl-4 mb-4">
            <h3 class="mb-3 font-weight-bold dark-grey-text">
              <strong>{{ item.name }}</strong>
            </h3>
            <p class="grey-text">{{ item.describe }}</p>
            <a href="{{ url_for('poly.detail', crawler_id=item.id) }}" target="_blank"
              class="btn btn-primary btn-md">查看详情
              <i class="fas fa-info ml-2"></i>
            </a>
            {% if current_user.is_subscribing(item) %}
                <button class="btn btn-outline-primary btn-md" onclick="unsubscribe({{ item.id }})">取消订阅<i class="fas fa-trash ml-2"></i></button>
            {% else %}
            <a href="{{ url_for('user.sub_add', crawler_id=item.id) }}" class="btn btn-primary btn-md">添加订阅
              <i class="fas fa-play ml-2"></i>
            </a>
            {% endif %}
          </div>
          <!--Grid column-->
        </div>
        <hr class="mb-5">
    {% endfor %}
    {% else %}
        <div class="row mt-3 wow fadeIn text-center container">
            <p>该分类下没有订阅</p>
        </div>
    {% endif %}
  </section>
{% endblock %}

{% block js %}
    <script>
        function unsubscribe(crawler_id) {
            var csrftoken = "{{ csrf_token() }}";
            $.ajax({
                url:"/user/unsubscribe/" + crawler_id,
                headers: {"X-CSRFToken": csrftoken},
                type: "POST",
                success: function (data) {
                    location.reload();
                },
              });
                }
    </script>
{% endblock %}